<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通知管理列表</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body>


<div class="layui-fluid">
    <div class="layui-card content-wrap">
        <!--查询-->
        <!--<div class="layui-form layui-card-header layuiadmin-card-header-auto">-->
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">公告标题</label>
                        <div class="layui-input-block">
                            <input type="text" id="noticeTitle" placeholder="请输入公告标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">公告内容</label>
                        <div class="layui-input-block">
                            <input type="text"  id="noticeContent" placeholder="请输入公告内容" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">发布人</label>
                        <div class="layui-input-block">
                            <input type="text" id="publisher" placeholder="请输入发布人" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">发布时间起</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="fromTime" placeholder="发布时间起" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">发布时间至</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="toTime" placeholder="发布时间止" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm4">

                        <a id="doSearch" class="layui-btn add_btn"><i class="layui-icon layui-icon-search"></i>搜索</a>
                        <button type="reset" class="layui-btn delete_btn"><i class="layui-icon layui-icon-delete"></i>清空</button>
                    </div>

                </div>
            </div>
        </form>


        <!--数据列表展示-->
        <div>
            <script type="text/html" id="optToolbar">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn" lay-event="addNotice" ><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>
                    <button class="layui-btn layuiadmin-btn-useradmin change_btn" lay-event="updateNotice" ><i class="layui-icon layui-icon-edit"></i>编辑</button>
                    <button class="layui-btn layuiadmin-btn-useradmin delete_btn" lay-event="delNotice"><i class="layui-icon layui-icon-delete"></i>删除</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn" lay-event="viewNotice">查看</button>
                </div>
            </script>

            <table class="layui-hide" id="dataListTable"
                   lay-filter="active"></table>
        </div>


    </div>
</div>


</body>

<script>

    var table;
    var tableObj;

    layui.use(['table','form','laydate','layer','element'], function() {
        table = layui.table;
        var form = layui.form,
            layDateFrom = layui.laydate,
            layDateTo = layui.laydate,
            layer=layui.layer;

        // 初始化日期控件
        var fromTime = layDateFrom.render({
            elem: '#fromTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    toTime.config.min = {
                        year: date.year,
                        month: date.month - 1,//关键
                        date: date.date,
                        hours: date.hours,
                        minutes: date.minutes,
                        seconds: date.seconds
                    };
                }
            }
            // ,range: true
        });
        var toTime = layDateTo.render({
            elem: '#toTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    fromTime.config.max = {
                        year: date.year,
                        month: date.month - 1,//关键
                        date: date.date,
                        hours: date.hours,
                        minutes: date.minutes,
                        seconds: date.seconds
                    };
                }
            }
            // ,range: true
        });

        tableObj = ax.VTable({
            id: 'loadDataList',
            elem : '#dataListTable',
            url : backendWebUrl + '/api/notice/list',
            toolbar: '#optToolbar',
            title:'通知列表',
            cols : [ [
                {type : 'checkbox', fixed : 'left' },
                {type: 'numbers', width : 80, title : '序号', fixed : 'left'},
                {field : 'noticeTitle', title : '标题', width : 200, fixed : 'left' },
                {field : 'tipsTime', width : 200, title : '弹窗时间' },
                {field : 'isTips', width : 100, title : '是否弹窗' },
                {field : 'dispenseOrg', minWidth : 200, title : '权限' },
                {field : 'publisher', width : 120, title : '发布人' },
                {field : 'publishTime', width : 180, title : '发布时间'}
                ] ]

        });

        var $ = layui.$;

        $('#doSearch').on('click', function(){
            searchData();
        });

        //头工具栏事件
        table.on('toolbar()', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'delNotice':
                    var data = checkStatus.data;
                    if(data.length<=0) {
                        top.layer.open({
                            title: '信息提示'
                            ,content: '请选择删除的数据！'
                        });
                        break;
                    }
                    top.layer.confirm('确定需要删除选中的通知！', function (index) {
                        top.layer.closeAll('dialog');
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id);
                        }
                        delNotice(ids.join(","));
                    });

                    break;
                case 'addNotice':
                    top.layer.open({
                        type: 2,
                        area: ['80%', '80%'],
                        fixed: true, //不固定
                        maxmin: true,
                        content: './aos/notice/edit.html'
                    });
                    break;
                case 'updateNotice':
                    var data = checkStatus.data;
                    if(data.length<=0) {
                        top.layer.open({
                            title: '信息提示'
                            ,content: '请选择编辑的数据！'
                        });
                        break;
                    }
                    top.layer.open({
                        type: 2,
                        area: ['80%', '80%'],
                        fixed: true, //不固定
                        maxmin: true,
                        content: './aos/notice/edit.html?id=' + data[0].id
                    });
                    break;
                case 'viewNotice':
                    var data = checkStatus.data;
                    if(data.length<=0) {
                        top.layer.open({
                            title: '信息提示'
                            ,content: '请选择查看的数据！'
                        });
                        break;
                    }
                    top.layer.open({
                        type: 2,
                        area: ['80%', '80%'],
                        fixed: true, //不固定
                        maxmin: true,
                        content: './aos/notice/preview.html?id=' + data[0].id
                    });
                    break;
            };
        });

    });

    function searchData() {
        //执行重载
        tableObj.reload({
            page : {
                curr: 1 //重新从第 1 页开始
            },
            where : {
                noticeTitle : $('#noticeTitle').val(),
                noticeContent : $('#noticeContent').val(),
                publisher : $('#publisher').val(),
                fromTime : $('#fromTime').val(),
                toTime : $('#toTime').val()
            }
        });
    }

    //删除通知
    function delNotice(ids) {
        var data={ids:ids};
        ax.get({
            url:backendWebUrl + "/api/notice/delete",
            data:data,
            success:function (res) {
                if(res.code == 0) {
                    top.layer.msg("删除成功");
                    searchData();
                } else {
                    top.layer.msg(res.msg);
                }
            },
            error : function(request) {
                top.layer.msg("系统错误，联系管理员");
            }
        });
    }
</script>
</html>